package com.jiaai.web.live;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.filter.aop.TokenIntercept;
import com.jiaai.live.api.ITagAPi;
import com.jiaai.live.model.VTag;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author 佳爱网络科技
 * @version V1.0
 * @title TagController
 * @since 2017/10/30
 */
@RestController
@RequestMapping("/api/v1/tag")
public class TagController {
    @Reference
    private ITagAPi tagAPi;

    @PostMapping("/add")
    @TokenIntercept(checkVisitor = true)
    public Object addTag(VTag tag) {
       try{
           tagAPi.addTag(tag);
           return RestResultGenerator.genSuccessResult("添加成功");
       }catch (Exception e){
           return RestResultGenerator.genErrorResult("服务器异常");
       }
    }

    @GetMapping("/del")
    @TokenIntercept(checkVisitor = true)
    public Object delTag(Integer id) {
        try{
            tagAPi.delTag(id);
            return RestResultGenerator.genSuccessResult("删除成功");
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("服务器异常");
        }
    }

    @GetMapping("/all")
    public Object selectByAll() {
        try {
            return  RestResultGenerator.genSuccessResult(tagAPi.selectByAll()) ;
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("服务器异常");
        }

    }

    @GetMapping("/rand")
    public Object selectRand() {
        try {
            return  RestResultGenerator.genSuccessResult(tagAPi.selectRand()) ;
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("服务器异常");
        }

    }



}
